package com.nbicc.file.bo;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.File;

@ApiModel(value = "文件系统中 文件描述信息" , description = "详细使用 参:README")
@Data
public class FileDesc {

    @ApiModelProperty(value="文件序列号")
    @JsonSerialize(using= ToStringSerializer.class)
    private Long id;
    @ApiModelProperty("文件原名")
    private String name;
    @ApiModelProperty("按日期生成存储路径(文件夹)")
    @JsonIgnore
    private String relativeFolder;
    @ApiModelProperty("文件起始位置")
    private long pos;
    @ApiModelProperty("文件长度")
    private long length;
    @ApiModelProperty("在文件系统中 已存储的长度")
    private long size = 0;
    @ApiModelProperty("文件是否完整")
    private boolean segment;

    /**
     * 相对路径(没有根路径)
     * @return
     */
    @JsonIgnore
    public String getRelativePath(){
        String fullPath =relativeFolder +
                        File.separator +
                        id+name.substring(name.lastIndexOf("."));
        return fullPath;
    }

    public void addSize(long size){
        if(this == null){
            this.size = size;
        }else{
            this.size += size;
        }
    }

}
